/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_ora_is_sql_dml.c                                 */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/17 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>

#include "frcomm.h"

#include "../../../../src/module/oracle/config.h"
#include <oracle/comm/ora_comm.h>

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

/**
 * 异常测试
 * select 语句
 */
static void __case1(void)
{
    char *p_sql = (char *) "select X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

/**
 * 正常测试
 * insert 语句
 */
static void __case2(void)
{
    char *p_sql = (char *) "insert X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_SUCC);
}

/**
 * 正常测试
 * update 语句
 */
static void __case3(void)
{
    char *p_sql = (char *) "update X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_SUCC);
}

/**
 * 正常测试
 * delete 语句
 */
static void __case4(void)
{
    char *p_sql = (char *) "delete X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_SUCC);
}

/**
 * 正常测试
 * merge 语句
 */
static void __case5(void)
{
    char *p_sql = (char *) "merge X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_SUCC);
}

/**
 * 异常测试
 * create 语句
 */
static void __case6(void)
{
    char *p_sql = (char *) "create X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

/**
 * 异常测试
 * drop 语句
 */
static void __case7(void)
{
    char *p_sql = (char *) "drop X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

/**
 * 异常测试
 * grant 语句
 */
static void __case8(void)
{
    char *p_sql = (char *) "grant X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

/**
 * 异常测试
 * commit 语句
 */
static void __case9(void)
{
    char *p_sql = (char *) "commit";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

/**
 * 异常测试
 * rollback 语句
 */
static void __case10(void)
{
    char *p_sql = (char *) "rollback";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

/**
 * 异常测试
 * alter 语句
 */
static void __case11(void)
{
    char *p_sql = (char *) "alter X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

/**
 * 异常测试
 * desc 语句
 */
static void __case12(void)
{
    char *p_sql = (char *) "desc X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

/**
 * 异常测试
 * show 语句
 */
static void __case13(void)
{
    char *p_sql = (char *) "show X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

/**
 * 异常测试
 * truncate 语句
 */
static void __case14(void)
{
    char *p_sql = (char *) "truncate X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

/**
 * 异常测试
 * revoke 语句
 */
static void __case15(void)
{
    char *p_sql = (char *) "revoke X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

/**
 * 异常测试
 * begin 语句
 */
static void __case16(void)
{
    char *p_sql = (char *) "begin X";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

/**
 * 异常测试
 * savepoint 语句
 */
static void __case17(void)
{
    char *p_sql = (char *) "savepoint";
    CU_ASSERT_EQUAL(ora_is_sql_dml(p_sql, strlen(p_sql)), FR_FAIL);
}

int add_suite_ora_is_sql_dml(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" ora_is_sql_dml()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL ||
        CU_add_test(pSuite, "case6", __case6) == NULL ||
        CU_add_test(pSuite, "case7", __case7) == NULL ||
        CU_add_test(pSuite, "case8", __case8) == NULL ||
        CU_add_test(pSuite, "case9", __case9) == NULL ||
        CU_add_test(pSuite, "case10", __case10) == NULL ||
        CU_add_test(pSuite, "case11", __case11) == NULL ||
        CU_add_test(pSuite, "case12", __case12) == NULL ||
        CU_add_test(pSuite, "case13", __case13) == NULL ||
        CU_add_test(pSuite, "case14", __case14) == NULL ||
        CU_add_test(pSuite, "case15", __case15) == NULL ||
        CU_add_test(pSuite, "case16", __case16) == NULL ||
        CU_add_test(pSuite, "case17", __case17) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
